"""
简化的API接口
"""

from fastapi import APIRouter, HTTPException
from app.services.core_service import CoreService
from typing import Dict, Any

router = APIRouter(prefix="/api", tags=["核心分析"])

# 全局服务实例 - 延迟初始化
core_service = None

@router.on_event("startup")
async def startup_event():
    """启动时初始化"""
    global core_service
    core_service = CoreService()
    core_service.initialize()

@router.post("/analyze")
async def analyze_news(request: Dict[str, Any]):
    """分析快讯"""
    try:
        if core_service is None:
            raise HTTPException(status_code=503, detail="服务未初始化")
        result = core_service.analyze_news(request)
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@router.get("/health")
async def health_check():
    """健康检查"""
    return {"status": "ok"}

